home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
generatr
/
cut.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-16
|
8KB
|
320 lines
#include <bitmap.h>
#include <extdefs.h>
#include <osbind.h>
#include <stdio.h>
#include <gemdefs.h>
extern int work_out[];
/* See if the screen is blank */
int search_blank(pointer)
long *pointer;
{
int i;
for( i=0; i<8000; i++ ) if( *pointer++ ) return( 1 );
return( 0 );
}
/* Interact with the user to get the coordinates of the box */
int cut_image(pointer,old_cutflag)
long pointer;
int old_cutflag;
{
char junk[20];
int flag;
int cflag;
int horizontal[4];
int vertical[4];
int rectangle[10];
long oldscreen;
int oldx, oldy;
int new_cutflag;
int x, y;
switch( rez ){
case 0: x = 1; y = 1; break;
case 1: x = 2; y = 1; break;
case 2: x = 2; y = 2; break;
}
/* wait for the mouse button to be released */
do{ GET_MOUSE; } while( button );
/* Get the current screen location */
oldscreen = Physbase();
HIDE_MOUSE;
Setscreen( pointer, pointer, -1 ); /* Show the screen */
vswr_mode( handle, 3 );
vsl_color( handle, 1 );
horizontal[0] = 0;
horizontal[2] = work_out[0];
horizontal[1] = horizontal[3] = my;
vertical[1] = 0;
vertical[3] = work_out[1];
vertical[0] = vertical[2] = mx;
flag = 0;
do{
if( my > 8 * y ) cflag = 1;
else cflag = 3;
text_box( pointer, temp_scrn, 0, cflag );
do{
/* Draw the lines */
horizontal[1] = horizontal[3] = my;
vertical[0] = vertical[2] = mx;
v_pline( handle, 2, horizontal );
v_pline( handle, 2, vertical );
do{ GET_MOUSE;
} while((Bconstat(2)==0)&&(button==0)&&(mx==oldx)&&(my==oldy));
v_pline( handle, 2, horizontal );
v_pline( handle, 2, vertical );
sprintf( junk, "X:%03d Y:%03d", mx, my );
if( cflag == 1 && my < 8 * y ){
cflag = 3;
text_box( pointer, temp_scrn, 1, 1 );
text_box( pointer, temp_scrn, 0, 3 );
}
else if( cflag == 3 && my > 191 * y ){
cflag = 1;
text_box( pointer, temp_scrn, 1, 3 );
text_box( pointer, temp_scrn, 0, 1 );
}
vswr_mode( handle, 1 );
switch( cflag ){
case 1: v_gtext( handle, 0, 6*y, junk );
break;
case 3: v_gtext( handle, 0, 198*y, junk );
break;
}
vswr_mode( handle, 3 );
oldx = mx; oldy = my;
} while( button == 0 && Bconstat(2) == 0 );
text_box( pointer, temp_scrn, 1, cflag );
if( Bconstat(2) != 0 )
{
Bconin(2);
new_cutflag = old_cutflag;
break;
}
do{ GET_MOUSE; } while( button );
/* define the constant coordinates for the rubber band box */
rectangle[0] = rectangle[6] = rectangle[8] = mx;
rectangle[1] = rectangle[3] = rectangle[9] = my;
if( my > 8 * y ) cflag = 1;
else cflag = 3;
text_box( pointer, temp_scrn, 0, cflag );
do{
/* define/change the variable rubber band box coordinates */
rectangle[2] = rectangle[4] = mx;
rectangle[5] = rectangle[7] = my;
v_pline( handle, 5, rectangle );
sprintf( junk, "W:%03d H:%03d", abs( rectangle[0] - rectangle[2] ) + 1, abs( rectangle[1] - rectangle[5] ) + 1 );
if( !cflag ){
if( rectangle[1] > 8*y && rectangle[5] > y*8 ) cflag = 1;
else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
if( cflag ){
v_pline( handle, 5, rectangle );
text_box( pointer, temp_scrn, 0, cflag );
v_pline( handle, 5, rectangle );
}
}
else if( cflag == 1 && ( rectangle[1] < y*8 || rectangle[5] < y*8 ) && ( rectangle[0] < x*160 || rectangle[2] < x*160 ) ){
if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 3;
else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 4;
else cflag = 0;
v_pline( handle, 5, rectangle );
text_box( pointer, temp_scrn, 1, 1 );
if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
v_pline( handle, 5, rectangle );
}
else if( cflag == 2 && ( rectangle[1] < y*8 || rectangle[5] < y*8 ) && ( rectangle[0] > x*160 || rectangle[2] > x*160 ) ){
if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 3;
else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 4;
else cflag = 0;
v_pline( handle, 5, rectangle );
text_box( pointer, temp_scrn, 1, 2 );
if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
v_pline( handle, 5, rectangle );
}
else if( cflag == 3 && ( rectangle[1] > y*191 || rectangle[5] > y*191 ) && ( rectangle[0] < x*160 || rectangle[2] < x*160 ) ){
if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 4;
else if( rectangle[1] > y*8 && rectangle[5] > y*8 ) cflag = 1;
else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
else cflag = 0;
v_pline( handle, 5, rectangle );
text_box( pointer, temp_scrn, 1, 3 );
if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
v_pline( handle, 5, rectangle );
}
else if( cflag == 4 && ( rectangle[1] > y*191 || rectangle[5] > y*191 ) && ( rectangle[0] > x*160 || rectangle[2] > x*160 ) ){
if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 3;
else if( rectangle[1] > y*8 && rectangle[5] > y*8 ) cflag = 1;
else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
else cflag = 0;
v_pline( handle, 5, rectangle );
text_box( pointer, temp_scrn, 1, 4 );
if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
v_pline( handle, 5, rectangle );
}
vswr_mode( handle, 1 );
switch( cflag ){
case 0: break;
case 1: v_gtext( handle, 0, 6*y, junk );
break;
case 2: v_gtext( handle, 160*x, 6*y, junk );
break;
case 3: v_gtext( handle, 0, 198*y, junk );
break;
case 4: v_gtext( handle, 160*x, 198*y, junk );
break;
}
vswr_mode( handle, 3 );
do{ GET_MOUSE;
} while((Bconstat(2)==0)&&(button==0)&&(mx==oldx)&&(my==oldy));
v_pline( handle, 5, rectangle );
oldx = mx; oldy = my;
} while( button == 0 && Bconstat(2) == 0 );
if( cflag ) text_box( pointer, temp_scrn, 1, cflag );
if( button )
{
new_cutflag = 1;
}
else
{
Bconin(2);
new_cutflag = 0;
}
} while( new_cutflag == 0 );
/* Make sure that the new screen is set */
Vsync();
SHOW_MOUSE;
do{ GET_MOUSE; graf_mkstate( &flag, &flag, &oldy, &flag ); }while( button || oldy );
oldx = evnt_multi( MU_MESAG|MU_TIMER, -1, -1, -1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
rectangle, 500, 0,
&flag, &flag, &flag, &flag, &flag, &flag );
/* Restore the old screen pointer */
Setscreen( oldscreen, oldscreen, -1 );
if( new_cutflag == 0 ) return(0);
rx1 = rectangle[0];
ry1 = rectangle[1];
rx2 = rectangle[4];
ry2 = rectangle[5];
return(1);
}/* End cut_image() function */
sscreen( mode )
int mode;
{
unsigned int i;
long *p1, *p2;
p1 = (long *)Physbase();
p2 = (long *)undo_scrn;
for( i=0; i<8000; i++ ){
if( mode == RESTORE ) *p1++ = *p2++;
else *p2++ = *p1++;
}
}
text_box( visual, remote, flag, cflag )
long *visual, *remote;
int flag, cflag;
{
int i, j, k, l;
if( rez == 2 )
k = 1, l = 2;
else
k = 2, l = 1;
switch( cflag ){
case 2: visual += 20L;
if( rez == 2 ) visual -= 10L;
break;
case 3: visual += 7680L;
break;
case 4: visual += 7700L;
if( rez == 2 ) visual -= 10L;
break;
}
for( i=0; i<8*l; i++ ){
for( j=0; j<k*10; j++ ){
if( !flag ) *remote++ = *visual++;
else *visual++ = *remote++;
}
if( rez != 2 )
visual += 20L;
else
visual += 10L;
}
}